package com.motus.pm.serviceImpl;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.motus.pm.dao.PhaseInfoDao;
import com.motus.pm.dao.ProjectInfoDao;
import com.motus.pm.dao.ProjectPhaseDao;
import com.motus.pm.service.ProjectService;
import com.motus.pm.vo.PmPhaseInfo;
import com.motus.pm.vo.PmProjectInfo;
import com.motus.pm.vo.PmProjectPhase;

@Service
@Transactional
public class ProjectServiceImpl implements ProjectService {
	
	@Autowired
	@Qualifier("phaseInfoDaoImpl")
	private PhaseInfoDao phaseInfoDao;
	@Autowired
	@Qualifier("projectInfoDaoImpl")
	private ProjectInfoDao projectInfoDao;
	@Autowired
	@Qualifier("projectPhaseDaoImpl")
	private ProjectPhaseDao projectPhaseDao;

	@Override
	public List<PmPhaseInfo> getAllPhaseInfos() {
		return phaseInfoDao.getAll();
	}

	@Override
	public PmPhaseInfo getPmPhaseById(String phaseId) {
		return phaseInfoDao.getById(phaseId);
	}
	
	
	@Override
	public void newProject(PmProjectInfo pmProjectInfo) {
		//此处只需保存projectinfo对象，因为hibernate中给关联对象配置了级联操作，
		//在保存projectInfo对象时同时会自动保存projectPhase对象
		projectInfoDao.save(pmProjectInfo);
	}

	@Override
	public PmProjectInfo getProjectInfoById(String pid) {
		return projectInfoDao.getById(pid);
	}

	@Override
	public List<PmProjectInfo> getProjectInfosByState(int proState) {
		return projectInfoDao.getProjectInfosByState(proState);
	}
	
	@Override
	public List<PmProjectInfo> getAllProjectInfos() {
		return projectInfoDao.getAll();
	}

	@Override
	public List<PmProjectPhase> getProjectPhasesByPid(String pid) {
		return projectPhaseDao.getProjectPhasesByPid(pid);
	}

	@Override
	public void updateProject(PmProjectInfo pmProjectInfo) {
		projectInfoDao.update(pmProjectInfo);
	}

	@Override
	public void deleteProject(PmProjectInfo pmProjectInfo) {
		projectInfoDao.delete(pmProjectInfo);
	}

}
